#!/bin/bash
#############################################
# author:fang
# version : v1.0
# name  : install
# dispcripe: install for linux bashrc
# CopyRight@fangyunjiang[42550564@qq.com]
#############################################
source ~/command/common

_src_path=~/command/linux
_backdir=".linux_backup"

function install_single()
{
    local src_file dest_file suffer
    src_file=$1;dest_file=$2
    suffer=$(date '+%Y-%m-%d-%H-%M-%S')
    echo "backup $dest_file"
    mv ~/${dest_file} ~/${_backdir}/${dest_file}-${suffer} 2>/dev/null
    echo "install $dest_file"
    cp ${_src_path}/$src_file ~/$dest_file
}

function install()
{
    cd ~
    mkdir -p ${_backdir}
    mkdir -p ~/.dest_path
    mkdir -p ~/.xn_history

    if ! __mac;then
      mkdir -p ~/.Trash
    fi
    if __mac || __linux;then
        sudo chmod 666 /etc/profile
        sudo sed -i '/\/etc\/bashrc/a\\t[ -r ~/.bashrc ] && . ~/.bashrc' /etc/profile
        sudo chmod 444 /etc/profile
    fi
    install_single bash/.bashrc .bashrc
    install_single bash/.vimrc .vimrc
    install_single bash/.inputrc .inputrc
    install_single bash/.gitconfig .gitconfig
    #install_single bash/.mongorc.js .mongorc.js
    if __windows;then
        install_single bash/.minttyrc .minttyrc
        install_single bash/.dir_colors .dir_colors
    fi
    if __cygwin;then
        cd ~
        ln -s $WINDOWS_HOME/AppData/Roaming/npm/node_modules node_modules
        [ -a /cygdrive/c ] &&  ln -s /cygdrive/c c
        [ -a /cygdrive/d ] &&  ln -s /cygdrive/d d
        [ -a /cygdrive/e ] &&  ln -s /cygdrive/e e
        [ -a /cygdrive/f ] &&  ln -s /cygdrive/f f
        cd /usr/local/bin/
        ln -s  $HOME/command/xnode node
    fi
}

install
